import { ref } from "vue";
import { defineStore } from "pinia";
import { getCurrentWindow, LogicalSize } from "@tauri-apps/api/window";

export const useAppStateStore = defineStore(
  "appState",
  () => {
    const appZoom = ref(100); // 100%
    const appSize = ref({
      width: 1280,
      height: 800,
    });

    async function setWinSize() {
      let win = getCurrentWindow();
      let sz = new LogicalSize(appSize.value.width, appSize.value.height);
      await win.setSize(sz);
    }

    function $reset() {
      appZoom.value = 100;
      appSize.value = {
        width: 1280,
        height: 800,
      };
    }

    return {
      appZoom,
      appSize,
      setWinSize,
      $reset,
    };
  },
  {
    persist: true,
  }
);
